<template>
  <div class="con">
    <h3>
      <span> 未完成</span>
      <button @click="change(0)">箭头</button>
    </h3>
    <ul v-show="active[0]">
      <li v-for="(item, index) in list" :key="index" v-show="item.status == 0">
        <input type="checkbox" v-model="item.status" @change="changeItem" />
        <p>{{ item.title }}</p>
        <button @click="changeStatus({ index, status: 2 })">取消</button>
      </li>
    </ul>
    <h3>
      <span> 已完成</span>
      <button @click="change(1)">箭头</button>
    </h3>
    <ul v-show="active[1]">
      <li v-for="(item, index) in list" :key="index" v-show="item.status == 1">
        <input type="checkbox" v-model="item.status" @change="changeItem" />
        <p>{{ item.title }}</p>
        <span>{{ item.time }}</span>
      </li>
    </ul>
    <h3>
      <span> 取消</span>
      <button @click="change(2)">箭头</button>
    </h3>
    <ul v-show="active[2]">
      <li v-for="(item, index) in list" :key="index" v-show="item.status == 2">
        <input type="checkbox" />
        <p>{{ item.title }}</p>
        <button @click="changeStatus({ index, status: 0 })">还原</button>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
  data() {
    return {
      active: [false, false, false],
    };
  },
  methods: {
    ...mapMutations(["changeItem", "changeStatus"]),
    change(index) {
      console.log(this.active[0]);

      // this.active[index] = !this.active[index];
      this.$set(this.active, index, !this.active[index]);
      //数据变了视图不变 用$set
    },
  },
  created() {},
  mounted() {},
  components: {},
  computed: {
    list() {
      return this.$store.state.list;
    },
  },
  watch: {},
};
</script>

<style lang="scss" scoped>
.con {
  h3 {
    display: flex;
    justify-content: space-between;
  }
  li {
    display: flex;
    justify-content: space-between;
  }
}
</style>
